<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class UserPost extends Model
{
    public static function getOne($id)
    {
        $post = self::find($id);
        if ($post) {
            $post = $post->toArray();
        }
        return $post;
    }

    public static function getPageList($where,$order = 'id', $sort = 'desc')
    {
        $posts = UserPost::where($where)->orderBy($order, $sort)->paginate(10)->toArray();
        return $posts;
    }

    public static function getUserPostCount($user_id)
    {
        $where = [
            ['user_id', '=', $user_id],
        ];
        return self::where($where)->count();
    }

    public static function getFeildCount($user_id, $field)
    {
        $where = [
            ['user_id', '=', $user_id],
        ];
        return self::where($where)->sum($field);
    }
}